<template>
  <div>
    <!-- <h1 v-focus>HelloB</h1> -->
    <h1>HelloB</h1>

    <p>JD100000000</p> <button v-copy="'JD100000000'">点我复制</button>
  </div>
</template>

<script>
export default {

  directives: {
    copy: function(el, binding) {
      el.onclick = function() {
        // console.log(binding.value)

        // 简单实现
        // 获取p标签的内容
        const pEl = document.querySelector('p')
        pEl.select()
        document.execCommand('Copy')
        alert('复制成功')
      }
    }
  },

  data() {
    return {
    };
  },
};
</script>
